<template>
  <p-modal
    :width="width"
    :class="getClass"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <template slot = "title">
        <p-row class="f-modal-title-row" type="flex">
          <p-col class="left">
            <slot name="title">{{ title }}</slot>
          </p-col>
          <p-col class="right" @click="toggleFullscreen(innerFullscreen)">
            <p-button class="poros-modal-close poros-modal-close-x" ghost type="link" :icon="fullscreenButtonIcon"/>
          </p-col>
        </p-row>
    </template>

    <p-spin :spinning="confirmLoading">
      <p-form :form="form">

        <p-row>
		  <p-col  :span="24">
			<p-form-item label="异常记录单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'abnormalRecordNo', validatorRules.abnormalRecordNo]" placeholder="请输入异常记录单号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="车间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly class="poros-input poros-input-disabled" v-decorator="[ 'workroomname', validatorRules.workroomname]" placeholder="请输入车间"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="车间编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly class="poros-input poros-input-disabled" v-decorator="[ 'workroomno', validatorRules.workroomno]" placeholder="请输入车间编码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="线体" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly class="poros-input poros-input-disabled" v-decorator="[ 'linename', validatorRules.linename]" placeholder="请输入线体"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="线体编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['lineno', validatorRules.lineno]"
						:trigger-change="true"
						org-fields="lineid,lineno,linename,workroomid,workroomno,workroomname"
						dest-fields="lineid,lineno,linename,workroomid,workroomno,workroomname"
						code="line_select"
						:add="this.url.add"
						isMultiSelect="popup"
						@oNvisible="oNvisible"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="班组" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly class="poros-input poros-input-disabled" v-decorator="[ 'classname', validatorRules.classname]" placeholder="请输入班组"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="班组编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['classno', validatorRules.classno]"
						:trigger-change="true"
						org-fields="id,classno,classname"
						dest-fields="id,classno,classname"
						code="mes_hr_q_classinfo"
						:add="this.url.add"
						isMultiSelect="popup"
						@oNvisible="oNvisible"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="工序工单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'processbillno', validatorRules.processbillno]" placeholder="请输入工序工单号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="二级工序编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'processTwocode', validatorRules.processTwocode]" placeholder="请输入二级工序编码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="二级工序名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'processTwoname', validatorRules.processTwoname]" placeholder="请输入二级工序名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="工站编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly class="poros-input poros-input-disabled" v-decorator="[ 'workstationcode', validatorRules.workstationcode]" placeholder="请输入工站编码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="工站名称 " :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly class="poros-input poros-input-disabled" v-decorator="[ 'workstationname', validatorRules.workstationname]" placeholder="请输入工站名称 "></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="问题大类" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'problemBig', validatorRules.problemBig]" placeholder="请输入问题大类"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="问题小类" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'problemSmall', validatorRules.problemSmall]" placeholder="请输入问题小类"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="问题等级" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'problemLevel', validatorRules.problemLevel]" placeholder="请输入问题等级"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="问题数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'problemNumber', validatorRules.problemNumber]" placeholder="请输入问题数量" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="负责人内码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'handlerId', validatorRules.handlerId]" placeholder="请输入负责人内码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="责任人工号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'handlerNo', validatorRules.handlerNo]" placeholder="请输入责任人工号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="责任人" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'handlerName', validatorRules.handlerName]" placeholder="请输入责任人"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="记录人 " :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'recordBy', validatorRules.recordBy]" placeholder="请输入记录人 "></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="记录时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'recordTime', validatorRules.recordTime]" placeholder="请输入记录时间"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="问题点描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'problemDescribe', validatorRules.problemDescribe]" placeholder="请输入问题点描述"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: "MesQcAbnormalRecordModal",
    mixins: [SubmitOnchangMixin],
    components: {
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        visible: false,
        model: {},
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          abnormalRecordNo: {rules: [
          ]},
          workroomname: {rules: [
            {required: true, message: '请输入车间!'},
          ]},
          workroomno: {rules: [
            {required: true, message: '请输入车间编码!'},
          ]},
          linename: {rules: [
            {required: true, message: '请输入线体!'},
          ]},
          lineno: {rules: [
            {required: true, message: '请输入线体编码!'},
          ]},
          classname: {rules: [
            {required: true, message: '请输入班组!'},
          ]},
          classno: {rules: [
            {required: true, message: '请输入班组编码!'},
          ]},
          processbillno: {rules: [
          ]},
          processTwocode: {rules: [
          ]},
          processTwoname: {rules: [
          ]},
          workstationcode: {rules: [
            {required: true, message: '请输入工站编码!'},
          ]},
          workstationname: {rules: [
            {required: true, message: '请输入工站名称 !'},
          ]},
          problemBig: {rules: [
          ]},
          problemSmall: {rules: [
          ]},
          problemLevel: {rules: [
          ]},
          problemNumber: {rules: [
          ]},
          handlerId: {rules: [
          ]},
          handlerNo: {rules: [
          ]},
          handlerName: {rules: [
          ]},
          recordBy: {rules: [
          ]},
          recordTime: {rules: [
          ]},
          problemDescribe: {rules: [
          ]},
        },
        url: {
          add: '/mes-quality/mesQcAbnormalRecord/add',
          edit: '/mes-quality/mesQcAbnormalRecord/edit',
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },

      edit (record,text) {
        this.form.resetFields();
        this.model = Object.assign({}, record,text);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'abnormalRecordNo','workroomname','workroomno','linename','lineno','classname','classno','processbillno','processTwocode','processTwoname','workstationcode','workstationname','mcode','mname','problemBig','problemSmall','problemLevel','problemNumber','handlerId','handlerNo','handlerName','recordBy','recordTime','problemDescribe'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
              that.confirmLoading = true;
              let httpurl = '';
              let method = '';
              let formData = Object.assign(this.model, values);
              this.formData = Object.assign(this.model, values);
              //新增触发
              if(!this.model.id || this.model.copy){
                httpurl+=this.url.add;
                method = 'post';
                if(this.EnhanceJS.afterAdd){
                  //新增之前
                  let Obj = eval(this.EnhanceJS.afterAdd)
                  new Obj(this)
                }else{
                  console.log("表单提交数据",formData)
                  that.modalFrom(httpurl,formData,method)
                }
              }else{
                //编辑触发
                httpurl+=this.url.edit;
                method = 'put';
                if(this.EnhanceJS.afterEdit){
                 //编辑之前
                  let Obj = eval(this.EnhanceJS.afterEdit)
                  new Obj(this)
                }else{
                  console.log("表单提交数据",formData)
                  that.modalFrom(httpurl,formData,method)
                }
              }
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'abnormalRecordNo','workroomname','workroomno','linename','lineno','classname','classno','processbillno','processTwocode','processTwoname','workstationcode','workstationname','mcode','mname','problemBig','problemSmall','problemLevel','problemNumber','handlerId','handlerNo','handlerName','recordBy','recordTime','problemDescribe'))
      },
    }
  }
</script>
<style lang="less">
@import '~@assets/less/common.less';
</style>
